package Config::System::t::Store;

use strict;
use warnings;
use Test::More;
use Test::Exception;
use IO::All -utf8;
use aliased 'Config::System::Store';

use base 'Test::Class';

my $File = 'store.properties';

sub create_file {
    my ($self, $config) = @_;
    io($File)->write($config);
    return Store->new(paths => [$File]);
}

sub rm_file: Test(teardown) { eval { io($File)->unlink } }

# tests ------------------------------------------------------------------------

sub simple: Test {
    my $self = shift;
    my $iut = $self->create_file("[Foo]\nBar=1");
    $iut->add_property(Foo => Bar => {isa => 'Num'});
    is $iut->get(Foo => 'Bar'), 1;
}

sub set_and_clone: Test(4) {
    my $self = shift;
    my $iut = Store->new;
    $iut->add_property(X => Y => {isa => 'Str'});
    $iut->set_expression(X => Y => ' "+" x 2 ');
    is $iut->get(X => 'Y'), '++';

    my $clone = $iut->clone;
    is $clone->get(X => 'Y'), '++';

    $iut->set(X => Y => '+');
    is $iut->get(X => 'Y'), '+';
    is $clone->get(X => 'Y'), '++';
}

1;
